<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="主键">

              <a-input placeholder="请输入主键" v-decorator="['id']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="创建人登录名称">

              <a-input placeholder="请输入创建人登录名称" v-decorator="['createBy']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="创建日期">

              <a-date-picker v-decorator="[ 'createTime' ]" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="更新人登录名称">

              <a-input placeholder="请输入更新人登录名称" v-decorator="['updateBy']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="更新日期">

              <a-date-picker v-decorator="[ 'updateTime' ]" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="用户名">

              <a-input placeholder="请输入用户名" v-decorator="['name']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="性别">

              <a-input placeholder="请输入性别" v-decorator="['sex']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="年龄">

              <a-input placeholder="请输入年龄" v-decorator="['age']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="描述">

              <a-input placeholder="请输入描述" v-decorator="['descc']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="生日">

              <a-date-picker v-decorator="[ 'birthday' ]" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="用户编码">

              <a-input placeholder="请输入用户编码" v-decorator="['userCode']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="附件">

              <a-input placeholder="请输入附件" v-decorator="['fileKk']" />
            </a-form-item>
          <a-form-item
           :labelCol="labelCol"
           :wrapperCol="wrapperCol"
           label="头像">

              <a-input placeholder="请输入头像" v-decorator="['topPic']" />
            </a-form-item>
        </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "test_demoModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{

        },
        url: {
          add: "/generator/test_demo/add",
          edit: "/generator/test_demo/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model
               ,createBy   ,createTime   ,updateBy   ,updateTime   ,name   ,sex   ,age   ,descc   ,birthday   ,userCode   ,fileKk   ,topPic                  ))

        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);

            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                                              }else{
                              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>